\section{Image preprocessing}

	To improve the recognition rate of the neural network, some data preprocessing could be used. Here is an image from the dataset used during the learning phase : 
	 \begin{figure}[H]
	 	\centering
	 	\includegraphics[scale=4]{img/Image1.png}
	 \end{figure}
	 
	As we can see, that image is noisy and has been a bit rotated. To improve learning and detecting stages a noise reduction and a reverse rotation can be applied.
	
	\subsection{Noise reduction}
	
		Noise reduction can be obtained by two classical image processing algorithms : erosion and binarization. First, the image average threshold, $t_{avg}$ is computed. Then a cross erosion is applied on the image with a threshold equal to $t_{avg}$. Afterwards, the resulting image is binarized. Finally, the binarized image is subtracted to the original one. The following image is the result of that preprocessing : 
	 	\begin{figure}[H]
	 		\centering
		 	\includegraphics[scale=4]{img/Image1_nr.png}
		 \end{figure}
		
	\subsection{Reverse rotation}
	
		To get all images in the same direction, an application of a reverse rotation needs to be done. First, the rotation angle need to be determined. This angle can be found by using the eyes on the image because they are always darkest part of the image. Detection of eye zone is done thanks to the following algorithm :
		\begin{verbatim}
			function subset(Position, listDarkestPosition, listAux) :
			    if(listPosion = nil) then 
			        return
			    else if (pixel at (x,y) has a neighbor) then
			        listAux.append(neighbor)
			        subset(neighbor.x, neighbor.y, tail(listDarkestPosition), listAux)
			    else
			        subset(x,y, tail(listDarkestPosition, listAux)
		\end{verbatim}
		
		Only the two largest subset will be considered because they are most probably the eyes. Then a vector is created between the middles of the eyes. The rotation angle corresponds to the angle between that vector and the vector $u = (1, 0)^T$. Reverse rotation is applied and if the image is upside down a symmetry  is computed.\\
		
		With such a preprocessing resulting images look like the following :
		\begin{figure}[H]
	 		\centering
		 	\includegraphics[scale=4]{img/Image1_fin.png}
		 \end{figure}
		